import {
	config
} from "@/config.js";
export const apiResquest = (prams) => {

	let headerData = {
		"content-type": "application/json",
		"token": uni.getStorageSync("token"),
	};
	return new Promise((resolve, reject) => {
		let url = config.base_url + prams.url; 
		uni.showLoading({
			title: "数据加载中",
			mask: true,
			icon: "loading"
		});
		return uni.request({
			url: url,
			data: prams.query,
			method: prams.method,
			header: headerData,
			success: (res) => {
				uni.hideLoading();
				if (res.data.code !== 200) {
					uni.showToast({
						title: "获取数据失败:" + res.data.message,
						duration: 1000,
						icon: "none",
					});
				}
				if (res.data.code === 401) {
					uni.reLaunch({
						url: "/pages/Login/Login"
					})
				}
				resolve(res.data);
			},
			fail: (err) => {
				reject(err);
				uni.hideLoading();
			},
			complete: () => {
				uni.hideLoading();
			},
		});
	});
};
